package com.zhuhjay.common.core.util;

import com.zhuhjay.common.security.LoginUserDetail;

import static com.zhuhjay.common.base.constant.ApplicationConstant.SUPER_ADMIN_ID;

/**
 * 增强SecurityContextHolder，便于使用
 * @author ZhuHJay
 * @date 2023/2/25 11:42
 */
public class SecurityContextHolder {

    /** 获取登录用户的token信息 **/
    public static LoginUserDetail getLoginUserDetail() {
        return (LoginUserDetail) org.springframework.security.core.context.SecurityContextHolder
                .getContext().getAuthentication().getPrincipal();
    }

    /**
     * 判断是否是超级管理员
     */
    public static boolean isAdmin() {
        return getLoginUserDetail().getId() == SUPER_ADMIN_ID;
    }

}
